package com.chenjt.jvm.third.vmops;

import java.util.ArrayList;

/**
 * 注释：
 *
 * 出现fullGC，不一定会OOM
 * 进行一次fullGC，就会生成一个hprof文件
 * -XX:+HeapDumpOnOutOfMemoryError -XX:+HeapDumpBeforeFullGC -XX:HeapDumpPath=D:\heapDumpInstance.hprof
 *
 *
 * @author chenjt
 * @date 2025/7/12 15:13
 */
public class HeapDumpInstance {

    private static int _1MB = 1024 * 1024;
    byte[] buffer = new byte[10 * _1MB];

    public static void main(String[] args) {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        ArrayList<HeapDumpInstance> list = new ArrayList<>();
        for (int i = 0; i < 500; i++) {
            list.add(new HeapDumpInstance());
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        System.out.println("程序执行结束");

    }

}
